package com.vhans.api.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.vhans.core.domain.Storage;
import com.vhans.db.service.IStorageService;
import com.vhans.core.web.controller.BaseController;
import com.vhans.core.web.model.Result;
import com.vhans.db.model.dto.ConditionDTO;
import com.vhans.db.model.dto.storage.StorageDTO;
import com.vhans.db.model.vo.storage.*;
import com.vhans.core.web.page.TableDataInfo;

import java.util.List;

/**
 * 存储Controller控制器
 * 
 * @author vhans
 * @date 2023-05-20
 */
@Api(tags = "存储模块")
@RestController
@RequestMapping("/dome/storage")
public class StorageController extends BaseController {
    @Autowired
    private IStorageService storageService;

    /**
     * 查询存储列表
     * @param condition 条件
     * @return {@link StorageVO} 题目列表
     */
    @ApiOperation(value = "查询存储列表")
    @SaCheckPermission("dome:storage:list")
    @GetMapping("/list")
    public TableDataInfo list(ConditionDTO condition) {
        startPage();
        List<StorageVO> list = storageService.selectStorageVOList(condition);
        return getDataTable(list);
    }

    /**
     * 获取存储详细信息
     * @param id 存储id
     * @return {@link Result<StorageInfoVO>} 存储信息
     */
    @ApiOperation(value = "获取存储编辑信息")
    @SaCheckPermission("dome:storage:query")
    @GetMapping(value = "/info/{id}")
    public Result<StorageInfoVO> getInfo(@PathVariable("id") Integer id) {
        return Result.success(storageService.selectStorageInfoById(id));
    }

    /**
     * 新增存储
     *
     * @param storage 存储信息
     * @return {@link Result<>}
     */
    @ApiOperation(value = "新增存储")
    @SaCheckPermission("dome:storage:add")
    @PostMapping("/add")
    public Result<Integer> add(@Validated @RequestBody StorageDTO storage) {
        Integer id = storageService.insertStorage(storage);
        return Result.success(id);
    }

    /**
     * 修改存储
     */
    @ApiOperation(value = "修改存储")
    @SaCheckPermission("dome:storage:update")
    @PutMapping("/updata")
    public Result<?> update(@Validated @RequestBody StorageDTO storage) {
        return toAjax(storageService.updateStorage(storage));
    }

    /**
     * 删除存储
     *
     * @param idList 需要删除的存储主键列表
     * @return {@link Result<>}
     */
    @ApiOperation(value = "删除存储")
    @SaCheckPermission("dome:storage:delete")
	@DeleteMapping("/delete")
    public Result<?> delete(@RequestBody List<Integer> idList) {
        return toAjax(storageService.deleteStorageByIdIdList(idList));
    }
}
